﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections;
using System.IO;
using System.Windows.Media.Animation;

namespace TouchUmlUI
{

    public class HintBoxBase : Canvas
    {
        double alpha = 0.0f;
        System.Windows.Forms.Timer Clock;
        public static Window1 windowParent;
        private bool hiding = false;
        public UMLObj umlObj;

        public bool isHiding()
        {
            return hiding;
        }
        
        public void startClock()
        {
            this.Opacity = 0.0f;
            Clock.Start();
        }

        public void setPosition(double px, double py)
        {
            InkCanvas.SetLeft(this, px);
            InkCanvas.SetTop(this, py);   
        }

        public HintBoxBase(double px,double py)
        {            
            this.Background = Brushes.Black;
            InkCanvas.SetLeft(this, px);
            InkCanvas.SetTop(this, py);            
            Clock = new System.Windows.Forms.Timer();
            Clock.Interval = 10;            
            Clock.Tick += new EventHandler(Timer_Tick);
            hiding = false;
        }

        public void setAlpha(double a)
        {
            this.Opacity = alpha;
        }

        public void Timer_Tick(object sender, EventArgs eArgs)
        {
            setAlpha(alpha);
            alpha += 0.05;
            if (alpha >= 0.95)
            {
                Clock.Stop();
            }
        }

        public void Hide(OurCanvas ourCanvas)
        {
            hiding = true;
            DoubleAnimation alphaAnimation = new DoubleAnimation();
            alphaAnimation.From = alpha;
            alphaAnimation.To = 0;
            alphaAnimation.Duration = new TimeSpan(0, 0, 0, 0, 500);
            alphaAnimation.Completed += delegate(object o, EventArgs eArgs)
            {
                if (ourCanvas.Children.Contains(this)) {
                    hiding = false;
                    ourCanvas.Children.Remove(this);                    
                }
            };
            this.BeginAnimation(Canvas.OpacityProperty, alphaAnimation);
        }


    }
}
